package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.GoodsEvaluateBatchMergeRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateCountRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateDeleteRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateIsPraiseRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateListRequest;
import com.frogs.ucenter.v1.request.GoodsEvaluateMergeRequest;
import com.frogs.ucenter.v1.service.GoodsEvaluateService;
import com.frogs.ucenter.v1.util.ApiConstants;

/**
 *
 * @author lijian
 * @version 2014年3月17日 - 上午9:52:16
 */
@Controller(ApiConstants.VERSION+"goodsEvaluateController")
@RequestMapping("/"+ApiConstants.VERSION)
public class GoodsEvaluateController extends BaseController3 {

	private static final String ROOT = "/goods";
	private static final String GOODS_EVALUATE_MERGE = ROOT + "/evaluate/merge";
	private static final String GOODS_EVALUATE_DELETE = ROOT + "/evaluate/delete";
	private static final String GOODS_EVALUATE_IS_PRAISE = ROOT + "/evaluate/isPraise";
	private static final String GOODS_EVALUATE_LIST = ROOT + "/evaluate/list";
	private static final String GOODS_EVALUATE_COUNT = ROOT + "/evaluate/count";
	private static final String GOODS_EVALUATE_BATCH_MERGE = ROOT + "/evaluate/batchMerge";
	
	@Resource(name=ApiConstants.VERSION + "goodsEvaluateService")
	private GoodsEvaluateService goodsEvaluateService;
	
	/**
	 * 商品评价接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(GOODS_EVALUATE_BATCH_MERGE)
	public Response batchMerge(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateBatchMergeRequest batchMergeRequest = new GoodsEvaluateBatchMergeRequest();
			batchMergeRequest.parse(request);
			response = goodsEvaluateService.batchMergeEvaluateInfo(batchMergeRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 商品评价接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/goods/evaluate/merge.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(GOODS_EVALUATE_MERGE)
	public Response goodsEvaluateMerge(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateMergeRequest evaluateRequest = new GoodsEvaluateMergeRequest();
			evaluateRequest.parse(request);
			response = goodsEvaluateService.mergeEvaluateInfo(evaluateRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 删除商品评价接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/goods/evaluate/delete.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(GOODS_EVALUATE_DELETE)
	public Response goodsEvaluateDelete(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateDeleteRequest evaluateRequest = new GoodsEvaluateDeleteRequest();
			evaluateRequest.parse(request);
			response = goodsEvaluateService.deleteGoodsEvaluateInfo(evaluateRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 商品评价-赞/踩接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/goods/evaluate/isPraise.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(GOODS_EVALUATE_IS_PRAISE)
	public Response goodsEvaluateIsPraise(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateIsPraiseRequest evaluateIsPraiseRequest = new GoodsEvaluateIsPraiseRequest();
			evaluateIsPraiseRequest.parse(request);
			response = goodsEvaluateService.isPraise(evaluateIsPraiseRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 获取商品评价接口
	 * 
	 * @param request
	 * @return
	 * 
	 * url :http://api.uc.frogshealth.com/v1/goods/evaluate/list.jsonp?uuid=1&token=1&uid=1&callback=test
	 */
	
	@RequestMapping(GOODS_EVALUATE_LIST)
	public Response goodsEvaluateList(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateListRequest evaluateListRequest = new GoodsEvaluateListRequest();
			evaluateListRequest.parse(request);
			response = goodsEvaluateService.getGoodsEvaluateList(evaluateListRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	/**
	 * 获取商品评价总数接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(GOODS_EVALUATE_COUNT)
	public Response goodsEvaluateCount(HttpServletRequest request) {
		Response response;
		try {
			GoodsEvaluateCountRequest evaluateCountRequest = new GoodsEvaluateCountRequest();
			evaluateCountRequest.parse(request);
			response = goodsEvaluateService.getEvaluateCount(evaluateCountRequest);
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
}
